package com.ywk.effective._8_transitivity;

import java.awt.*;

class ColorPoint extends Point {
    private Color color;

    public ColorPoint(int x, int y, Color color) {
        super(x, y);
        this.color = color;
    }

    @Override
    public boolean equals(Object obj) {
        /*if (!(obj instanceof ColorPoint)) {
            return false;
        }*/
        if (!(obj instanceof Point)) {
            return false;
        }
        if (!(obj instanceof ColorPoint)) {
            return super.equals(obj);
        }

        return super.equals(obj) && ((ColorPoint) obj).color == color;
    }

    static class Main {
        public static void main(String[] args) {
            Point point = new Point(1, 2);
            ColorPoint colorPoint = new ColorPoint(1, 2, Color.RED);
            ColorPoint colorPoint2 = new ColorPoint(1, 2, Color.RED);
            System.out.println(point.equals(colorPoint));
            System.out.println(colorPoint.equals(point));
            System.out.println(colorPoint.equals(colorPoint2));
            System.out.println(point.getClass() + ":" + colorPoint.getClass() + " " +
                    (point.getClass() == colorPoint.getClass()));

        }
    }
}
